//
//  StoreDataAlertView.m
//  GLGW_Shoping
//
//  Created by whx on 2018/12/11.
//  Copyright © 2018年 yang. All rights reserved.
//

#import "StoreDataAlertView.h"

@interface StoreDataAlertView ()
{
    NSString *textFStr;
    GLGWView *alerView;
}

@property (nonatomic, strong) GLGWTextView *textView;
@end

@implementation StoreDataAlertView

- (id)initStoreDataAlertView
{
    if (self = [super initWithFrame:kAppWindow.bounds inSuperView:kAppWindow]) {
        GLGWView *baView = [[GLGWView alloc] initWithInSuperView:self];
        [baView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self).offset(0);
            make.left.equalTo(self).offset(0);
            make.width.equalTo(@(KScreenWidth));
            make.height.equalTo(@(KScreenHeight));
        }];
        //
        baView.backgroundColor = [UIColor colorWithHexString:@"#000000" alpha:0.5];
        
        GLGWView *alerV = [[GLGWView alloc] initWithInSuperView:baView];
        alerV.backgroundColor = [UIColor colorWithHexString:@"#FFFFFF"];
        alerV.layer.cornerRadius = kHeightProportion_In_iPhoneTriploid(12);
        [alerV mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(baView.mas_left).offset(kWidthProportion_In_iPhoneTriploid(52));
            make.right.equalTo(baView.mas_right).offset(-kWidthProportion_In_iPhoneTriploid(53));
            make.top.equalTo(baView.mas_top).offset(kHeightProportion_In_iPhoneTriploid(228));
            make.height.equalTo(@(kHeightProportion_In_iPhoneTriploid(184)));
        }];
        alerView.clipsToBounds = YES;
        alerView = alerV;
        
        GLGWLabel *titleLab = [[GLGWLabel alloc] initWithFont:SYSTEMFONT(14) theColor:kColor_Rule_Black inSuperView:alerV];
        titleLab.text = @"添加店铺优势";
        [titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(alerV.mas_top).offset(kHeightProportion_In_iPhoneTriploid(14));
            make.centerX.equalTo(alerV.mas_centerX);
            make.height.equalTo(@(kHeightProportion_In_iPhoneTriploid(20)));
        }];
        
//        GLGWTextField *textF = [[GLGWTextField alloc] initTitlePlaceholder:@"请输入关键字（10字以内）" theFont:SYSTEMFONT(16) theTitColor:kColor_Rule_Black inSuperView:alerV];
//        [textF mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.left.equalTo(alerV.mas_left).offset(kWidthProportion_In_iPhoneTriploid(10));
//            make.top.equalTo(titleLab.mas_bottom).offset(kHeightProportion_In_iPhoneTriploid(33));
//            make.height.equalTo(@(kHeightProportion_In_iPhoneTriploid(22)));
//            make.right.equalTo(alerV.mas_right).offset(-kWidthProportion_In_iPhoneTriploid(15));
//        }];
//        textF.returnKeyType = UIReturnKeyDone;
//        @weakify(self);
//        [[[RACSignal merge:@[textF.rac_textSignal, RACObserve(textF, text)]] filter:^BOOL(NSString*  _Nullable value) {
//            return value.length < 10 ? YES : NO;
//        }] subscribeNext:^(NSString* text){
//            @strongify(self);
//            DLog(@"===%@",text);
//            self->textFStr = text;
//        }];
        
        UITextField *textF = [[UITextField alloc] init];
        textF.font = SYSTEMFONT(16);
        textF.textColor = kColor_Rule_Black;
        textF.returnKeyType = UIReturnKeyDone;
        [alerV addSubview:textF];
        [textF mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(alerV.mas_left).offset(kWidthProportion_In_iPhoneTriploid(10));
            make.top.equalTo(titleLab.mas_bottom).offset(kHeightProportion_In_iPhoneTriploid(33));
            make.height.equalTo(@(kHeightProportion_In_iPhoneTriploid(22)));
            make.right.equalTo(alerV.mas_right).offset(-kWidthProportion_In_iPhoneTriploid(15));
        }];
        textF.placeholder = @"请输入关键字（10字以内）";
        self.textFid = textF;
        
        [textF.rac_textSignal subscribeNext:^(NSString * _Nullable x) {
            if (x.length > 10) {
                self->textFStr = [x substringToIndex:10];
                textF.text = self->textFStr;
            } else {
                self->textFStr = x;
                textF.text = x;
            }
        }];
        
        GLGWButton *sureBtn = [[GLGWButton alloc] initWithTitle:@"确定" titleLableFont:SYSTEMFONT(16) titleLableColor:[UIColor colorWithHexString:@"#A89A60"] inSuperView:alerV];
        [sureBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(alerV.mas_bottom);
            make.right.equalTo(alerV.mas_right);
            make.width.equalTo(@(kWidthProportion_In_iPhoneTriploid(134)));
            make.height.equalTo(@(kHeightProportion_In_iPhoneTriploid(50)));
        }];
        [sureBtn addTarget:self action:@selector(sureAction:) forControlEvents:UIControlEventTouchUpInside];
        
        GLGWButton *cancelBtn = [[GLGWButton alloc] initWithTitle:@"取消" titleLableFont:SYSTEMFONT(16) titleLableColor:[UIColor colorWithHexString:@"#999999"] inSuperView:alerV];
        [cancelBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(alerV.mas_bottom);
            make.left.equalTo(alerV.mas_left);
            make.right.equalTo(sureBtn.mas_left).offset(kWidthProportion_In_iPhoneTriploid(1));
            make.height.equalTo(sureBtn.mas_height);
        }];
        [cancelBtn addTarget:self action:@selector(cancelAction:) forControlEvents:UIControlEventTouchUpInside];
        
        GLGWView *linV1 = [[GLGWView alloc] initWithInSuperView:alerV];
        linV1.backgroundColor = [UIColor colorWithHexString:@"#EAEAEA"];
        [linV1 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(cancelBtn.mas_top);
            make.left.right.equalTo(alerV);
            make.height.equalTo(@(1));
        }];

        GLGWView *linV2 = [[GLGWView alloc] initWithInSuperView:alerV];
        linV2.backgroundColor = [UIColor colorWithHexString:@"#EAEAEA"];
        [linV2 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(cancelBtn.mas_right).offset(1);
            make.top.bottom.equalTo(cancelBtn);
            make.width.equalTo(@(1));
        }];
        
        GLGWView *linV = [[GLGWView alloc] initWithInSuperView:alerV];
        linV.backgroundColor = [UIColor colorWithHexString:@"#EAEAEA"];
        [linV mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(alerV.mas_left).offset(kWidthProportion_In_iPhoneTriploid(10));
            make.right.equalTo(alerV.mas_right).offset(-kWidthProportion_In_iPhoneTriploid(10));
            make.height.equalTo(@(1));
            make.bottom.equalTo(sureBtn.mas_top).offset(-kHeightProportion_In_iPhoneTriploid(20));
        }];
    }
    return self;
}

- (void)sureAction:(GLGWButton *)sender
{
    if (self.BlockSure) {
        self.BlockSure(textFStr);
    }
    [self removeFromSuperview];
}

- (void)cancelAction:(GLGWButton *)sender
{
    if (self.BlockCancel) {
        self.BlockCancel(sender);
    }
    [self removeFromSuperview];
}

@end
